<template>
	<view>
		<!-- #ifdef MP-WEIXIN -->
		<rich-text class="rich" :nodes="ment|formatRichText"></rich-text>
		<!-- #endif -->

		<!-- #ifdef MP-ALIPAY -->
		<!-- <rich-text class="rich" :nodes="ment1"></rich-text> -->
		<rich-text class="rich" :nodes="ment1" selectable></rich-text>
		<!-- #endif -->
	</view>
</template>

<script>
	import parse from "@/node_modules/mini-html-parser2"
	export default {
		data() {
			return {
				ment: '',
				ment1: []
			}
		},
		onLoad() {
			// this.getMent()
			let config = uni.getStorageSync('config')
			this.ment = config.company_desc
			// parse(config.company_desc, (err, nodesList) => {
			// 	this.ment1 = this.ment1.concat(nodesList);
			// })
			let tempcontent = this.unescapeHTML(config.company_desc)
			console.log(tempcontent)
			parse(tempcontent, (err, data) => {
				if (!err) {
					this.ment1 = data
				}
			})
		},
		methods: {
			unescapeHTML(a) {
				a = "" + a;
				a = a.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&").replace(/&quot;/g, '"').replace(
					/&apos;/g, "'");
				a = a.replace(/\<img/gi,
					'<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
				return a;
			}
		},
		filters: {
			formatRichText(html) { //控制小程序中图片大小
				let newContent = html.replace(/<img[^>]*>/gi, function(match, capture) {
					match = match.replace(/style="[^"]+"/gi, '').replace(/style='[^']+'/gi, '');
					match = match.replace(/width="[^"]+"/gi, '').replace(/width='[^']+'/gi, '');
					match = match.replace(/height="[^"]+"/gi, '').replace(/height='[^']+'/gi, '');
					return match;
				});
				newContent = newContent.replace(/style="[^"]+"/gi, function(match, capture) {
					match = match.replace(/width:[^;]+;/gi, 'max-width:100%;').replace(/width:[^;]+;/gi, 'max-width:100%;');
					return match;
				});
				newContent = newContent.replace(/<br[^>]*\/>/gi, '');
				newContent = newContent.replace(/\<img/gi,
					'<img style="max-width:100%;height:auto;display:inline-block;margin:10rpx auto;"');
				return newContent;
			}
		}


	}
</script>

<style scoped lang="scss">

</style>
